package com.leyou.auth.service.impl;

import com.leyou.auth.service.AuthService;
import com.leyou.common.enums.ExceptionEnum;
import com.leyou.common.exceptiion.LyException;
import com.leyou.auth.client.UserClient;
import com.leyou.auth.config.JwtProperties;
import com.leyou.auth.entity.UserInfo;
import com.leyou.auth.utils.JwtUtils;
import com.leyou.user.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;

/**
 * @ClassName AuthServiceImpl
 * @Date 2019/2/25 19:24
 */
@Service
@EnableConfigurationProperties(JwtProperties.class)
public class AuthServiceImpl implements AuthService {

    @Autowired
    private UserClient userClient;
    
    @Autowired
    private JwtProperties prop;
    
    @Override
    public String login(String username, String password) {
        //校验用户名和密码
        /*User user = userClient.queryUserByNameAndPwd(username, password);
        if (user == null) {
            throw new LyException(ExceptionEnum.INVALID_USERNAME_AND_PASSWORD);
        }*/
        //生成token
        UserInfo userInfo = new UserInfo(1l, "WGC");
        String token = JwtUtils.generateToken(userInfo, prop.getPrivateKey(), prop.getExpire());
        return token;
    }
}
